<?php

namespace app\controller\system;

use app\BaseController;
use think\response\Json;

class Merchant extends BaseController
{
    public function save(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\Merchant::class)->insertData();
        });
    }

    public function lst(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\Merchant::class)->pageData();
        });
    }

    public function detail(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\Merchant::class)->where('id', $this->request->param("id"))->find();
        });
    }

    public function update_balance(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\Merchant::class)->updateBalance();
        });
    }

    public function balance(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\MerchantBalanceNotice::class)->pageData();
        });
    }

    public function search(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\Merchant::class)->search();
        });
    }

    public function serviceSave(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\MerchantService::class)->serviceSave();
        });
    }

    public function serviceLst(): Json
    {
        return $this->handle(function () {
            return $this->app->make(\app\model\MerchantService::class)->serviceLst();
        });
    }

    public function serviceDetail(): Json
    {
        return $this->handle(function () {
            $data = $this->app->make(\app\model\MerchantService::class)->where('id',$this->request->param('id'))->find();
            if(!empty($data)){
                $data = $data->toArray();
                $data['content'] = htmlspecialchars_decode($data['content']);
            }
            return $data;
        });
    }
}
